﻿using Loaf.Beans;
using Loaf.Tools;
using Prism.Commands;
using Prism.Mvvm;
using System.Windows;
using System.Windows.Input;

namespace Loaf.ViewModels
{
    public class SettingViewModel : BindableBase
    {
        public Context Context { get; set; }

        public List<HotkeyModifiers> HotkeyModifiersList { get; set; } = new List<HotkeyModifiers>() {
            HotkeyModifiers.None,
            HotkeyModifiers.Alt  ,
            HotkeyModifiers.Ctrl ,
            HotkeyModifiers.Shift,
            HotkeyModifiers.Win
        };
        public List<Key> HotKeyList { get; set; } = new List<Key>()
        {
            Key.Subtract,
            Key.Add,
            Key.PageUp,
            Key.PageDown,
            Key.End,
            Key.Home,
            Key.F12,
            Key.F11,
            Key.F10,
            Key.F9,
            Key.F8,
            Key.F7,
            Key.F6,
            Key.F5,
            Key.F4,
            Key.F3,
            Key.F2,
            Key.F1,
            Key.Q,
            Key.W,
            Key.E,
            Key.R,
            Key.T,
            Key.Y,
            Key.U,
            Key.I,
            Key.O,
            Key.P,
            Key.A,
            Key.S,
            Key.D,
            Key.F,
            Key.G,
            Key.H,
            Key.J,
            Key.K,
            Key.L,
            Key.Z,
            Key.X,
            Key.C,
            Key.V,
            Key.B,
            Key.N,
            Key.M
        };

        /// <summary>
        /// 热键
        /// </summary>
        public HotkeyModifiers HotkeyModifiersSelectedValue { get; set; }

        /// <summary>
        /// 按键
        /// </summary>
        public Key HotKeySelectedValue { get; set; }

        /// <summary>
        /// 设置快捷键
        /// </summary>
        public DelegateCommand SetHotKeyCommand { get; set; }


        public SettingViewModel(Context context)
        {
            Context = context;


            SetHotKeyCommand = new DelegateCommand(SetHotKeyAction);
        }

        /// <summary>
        /// 设置快捷键
        /// </summary>
        public void SetHotKeyAction()
        {
            Context.AppSetting.HotkeyModifiers = HotkeyModifiersSelectedValue;
            Context.AppSetting.Hotkey = HotKeySelectedValue;
            Context.WriteContext();
         }

    }
}
